using Digitalmes.Domain.Entities.Mes.Equipments;

namespace Digitalmes.Application.Mes.Equipments.Inspections.Queries;

/// <summary>
/// 自动点检项查询命令。
/// </summary>
/// <param name="PlanId">点检计划 Id</param>
public sealed record GetAutoInspectionItemListQuery(long PlanId) : IRequest<IResult<List<EquipAutoInspectionItemDto>>>;

internal sealed class GetAutoInspectionItemListQueryHandler(IRepository<EquipAutoInspectionItem> repo)
    : IRequestHandler<GetAutoInspectionItemListQuery, IResult<List<EquipAutoInspectionItemDto>>>
{
    public async Task<IResult<List<EquipAutoInspectionItemDto>>> Handle(GetAutoInspectionItemListQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetListAsync(m => m.PlanId == request.PlanId, cancellationToken);
        return Result.From(items.Adapt<List<EquipAutoInspectionItemDto>>());
    }
}
